package com.findmeastore.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.findmeastore.bo.BusinessAddress;
import com.findmeastore.bo.BusinessEntity;
import com.findmeastore.bo.ContactDetails;
import com.findmeastore.bo.RelBusinessCategory;
import com.findmeastore.bo.RelBusinessProduct;
import com.findmeastore.dao.IBusinessDAO;

public class BuinessDAOImpl implements IBusinessDAO{

	private HibernateTemplate hibernateTemplate;

	public void setSessionFactory(SessionFactory sessionFactory){
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}

	public BusinessEntity getBusinessEntity(Integer businessId) {
		return (BusinessEntity)hibernateTemplate.get(BusinessEntity.class, businessId);
	}

	public BusinessEntity saveBusiness(BusinessEntity businessEntity) {
		hibernateTemplate.save(businessEntity);
		return businessEntity;
	}

	public void saveBusinessAddress(BusinessAddress businessAddress) {
		hibernateTemplate.save(businessAddress);
	}

	public void saveBusinessContact(ContactDetails contactDetails) {
		hibernateTemplate.save(contactDetails);
	}

	public void saveBusinessCategory(RelBusinessCategory relBusinessCategory) {
		hibernateTemplate.save(relBusinessCategory);
	}

	public List<BusinessEntity> getAllBusiness() {
		return (List<BusinessEntity>)hibernateTemplate.find("from BusinessEntity");
	}

	public ContactDetails getBusinessContactById(Integer id) {
		return (ContactDetails)hibernateTemplate.get(ContactDetails.class, id);
	}
	
	public RelBusinessCategory getBusinessCatRelById(Integer id) {
		return (RelBusinessCategory)hibernateTemplate.get(RelBusinessCategory.class, id);
	}

	public RelBusinessProduct getBusinessProductRelById(Integer id) {
		return (RelBusinessProduct)hibernateTemplate.get(RelBusinessProduct.class, id);
	}

}
